package org.computer.hibernate.artifacts;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * Data access object (DAO) for domain model class OrderformInfo.
 * 
 * @see org.computer.hibernate.artifacts.OrderformInfo
 * @author MyEclipse Persistence Tools
 */

public class OrderformInfoDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(OrderformInfoDAO.class);

	// property constants
	public static final String VIRTUAL_NAME = "virtualName";

	public static final String REAL_NAME = "realName";

	public static final String REAL_ADDRESS = "realAddress";

	public static final String REAL_ZONE_ID = "realZoneId";

	public static final String ORDERFORM_STATUS = "orderformStatus";

	public static final String ORDERFORM_PASSWORD = "orderformPassword";

	protected void initDao() {
		// do nothing
	}

	public void save(OrderformInfo transientInstance) {
		log.debug("saving OrderformInfo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(OrderformInfo persistentInstance) {
		log.debug("deleting OrderformInfo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public OrderformInfo findById(java.lang.Integer id) {
		log.debug("getting OrderformInfo instance with id: " + id);
		try {
			OrderformInfo instance = (OrderformInfo) getHibernateTemplate()
					.get("org.computer.hibernate.artifacts.OrderformInfo", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(OrderformInfo instance) {
		log.debug("finding OrderformInfo instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding OrderformInfo instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from OrderformInfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByVirtualName(Object virtualName) {
		return findByProperty(VIRTUAL_NAME, virtualName);
	}

	public List findByRealName(Object realName) {
		return findByProperty(REAL_NAME, realName);
	}

	public List findByRealAddress(Object realAddress) {
		return findByProperty(REAL_ADDRESS, realAddress);
	}

	public List findByRealZoneId(Object realZoneId) {
		return findByProperty(REAL_ZONE_ID, realZoneId);
	}

	public List findByOrderformStatus(Object orderformStatus) {
		return findByProperty(ORDERFORM_STATUS, orderformStatus);
	}

	public List findByOrderformPassword(Object orderformPassword) {
		return findByProperty(ORDERFORM_PASSWORD, orderformPassword);
	}

	public List findAll() {
		log.debug("finding all OrderformInfo instances");
		try {
			String queryString = "from OrderformInfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public OrderformInfo merge(OrderformInfo detachedInstance) {
		log.debug("merging OrderformInfo instance");
		try {
			OrderformInfo result = (OrderformInfo) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(OrderformInfo instance) {
		log.debug("attaching dirty OrderformInfo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(OrderformInfo instance) {
		log.debug("attaching clean OrderformInfo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static OrderformInfoDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (OrderformInfoDAO) ctx.getBean("OrderformInfoDAO");
	}
}